
version 14.2
clear
log using "C:\Users\sgolder\Dropbox\OUP multilevel electoral behavior book\chapter 7\replication\ch7_setup.log", replace
set more off

use "C:\Users\sgolder\Dropbox\OUP multilevel electoral behavior book\chapter 7\replication\Merged data July 20 2016.dta\Merged data July 20 2016.dta", clear

*** social background
recode education (10 = 9) (11 = 9)
gen schooling=education-1

gen female=GEND
recode female (2 = 1) (1 = 0)
lab def female 0 "male" 1 "female"

gen age=ELYEAR-YOB

*** national economic evaluations DK coded as about the same
gen nationaleconomy=Q16 
recode nationaleconomy (1 = 0) (2 = 1) (3 = 2) (9 = 1)
lab def nationaleconomy 0 "worse" 1 "about the same" 2 "better"

*** Correcting coding for Bavaria EU
replace nationaleconomy=0 if Q16==3 & ELECID==19
replace nationaleconomy=2 if Q16==1 & ELECID==19

gen worsenational=nationaleconomy
replace worsenational=1 if nationaleconomy==0
replace worsenational=0 if nationaleconomy>0
lab def worsenational 0 "not worse" 1 "worse"

gen betternational=nationaleconomy
replace betternational=0 if nationaleconomy==1
replace betternational=1 if nationaleconomy==2
lab def betternational 0 "not better" 1 "better"

*** subnational economic evaluations DKs coded as about the same
gen regionaleconomy=Q15
recode regionaleconomy (1 = 0) (2 = 1) (3 = 2) (9 = 1)
lab def regionaleconomy 0 "worse" 1 "about the same" 2 "better"

gen worseregional=regionaleconomy
replace worseregional=1 if regionaleconomy==0
replace worseregional=0 if regionaleconomy>0
lab def worseregional 0 "not worse" 1 "worse"

gen betterregional=regionaleconomy
replace betterregional=0 if regionaleconomy==1
replace betterregional=1 if regionaleconomy==2
lab def betterregional 0 "not better" 1 "better"

*** national attributions of responsibility
gen nationalresponsibility=Q16A
recode nationalresponsibility (1 = 0) (2 = 1) (3 = 2) (9 =1 ) 
lab def nationalresponsibility 0 "worse" 1 "not much difference" 2 "better"

**** dichotomizes nationalresponsibility 
gen NATresp=nationalresponsibility
replace NATresp=1 if nationalresponsibility==0
replace NATresp=0 if nationalresponsibility>0
lab def NATresp 0 "not worse" 1 "worse"

***limits NATresp to those who thought economy had got worse

gen NATworse=NATresp if worsenational==1

**** national responsibility for improved economy

gen NATbetter=0 if betternational==1
replace NATbetter=. if betternational==0 
replace NATbetter=1 if nationalresponsibility==2 & betternational==1

*** creates 3 category variable for attributing responsibility

replace NATresp=2 if NATresp==1 & worsenational==1
replace NATresp=1 if NATresp==0 & worsenational==1
replace NATresp=0 if NATresp==0 & worsenational==0
replace NATresp=0 if NATresp==1 & worsenational==0

*** subnational attributions of responsibility
gen regionalresponsibility=Q15A
recode regionalresponsibility (1 = 0) (2 =1 ) (3 = 2) (9 = 1) 
lab def regionalresponsibility 0 "worse" 1 "not much difference" 2 "better"

**** dichotomizes regionalresponsibility 
gen REGresp=regionalresponsibility
replace REGresp=1 if regionalresponsibility==0
replace REGresp=0 if regionalresponsibility>0
lab def REGresp 0 "not worse" 1 "worse"

***limits REGresp to those who thought economy had got worse

gen REGworse=REGresp if worseregional==1

*** regional responsibility for improved economy

gen REGbetter=0 if betterregional==1
replace REGbetter=. if betterregional==0
replace REGbetter=1 if regionalresponsibility==2 & betterregional==1

*** Creates 3 category variable for attributing responsibility

replace REGresp=2 if REGresp==1 & worseregional==1
replace REGresp=1 if REGresp==0 & worseregional==1
replace REGresp=0 if REGresp==0 & worseregional==0
replace REGresp=0 if REGresp==1 & worseregional==0

*** attachments
gen regionalattach=Q43C
replace regionalattach=. if Q43C==99

gen nationalattach=Q43B
replace nationalattach=. if Q43B==99

gen attachdiff=nationalattach-regionalattach
gen regionmore=1 if attachdiff<0
replace regionmore=0 if attachdiff>-1
replace regionmore=. if nationalattach==.
replace regionmore=. if regionalattach==.
lab var regionmore "more attached to region"

gen nationalmore=1 if attachdiff>0
replace nationalmore=0 if attachdiff<1
replace nationalmore=. if nationalattach==.
replace nationalmore=. if regionalattach==.
lab var nationalmore "more attached to nation"

*** corruption DK coded as hardly any
gen nationalcorrupt=Q50B
recode nationalcorrupt (1 = 0) (2 = 1) (3 = 2) (4 = 3) (9 = 0) 

gen regionalcorrupt=Q50A
recode regionalcorrupt (1 = 0) (2 = 1) (3 = 2) (4 = 3) (9 = 0) 

gen municipalcorrupt=Q50C
recode municipalcorrupt (1 = 0) (2 = 1) (3 = 2) (4 = 3) (9 = 0) 

lab def nationalcorrupt 0 "hardly any" 1 "a little" 2 "some" 3 "a lot"
lab def regionalcorrupt 0 "hardly any" 1 "a little" 2 "some" 3 "a lot"
lab def municipalcorrupt 0 "hardly any" 1 "a little" 2 "some" 3 "a lot"

*** eliminate missing values for incumbent vote
replace INCUMBENT=. if INCUMBENT==99

*** party identification
gen partyID=0
replace partyID=1 if ELECID==5 & Q47A==2
replace partyID=1 if ELECID==5 & Q47A==9
replace partyID=1 if ELECID==6 & Q47A==2. 
replace partyID=1 if ELECID==6 & Q47A==9
replace partyID=1 if ELECID==7 & Q47A==1.
replace partyID=1 if ELECID==8 & Q47A==4. 
replace partyID=1 if ELECID==9 & Q47A==1
replace partyID=1 if ELECID==10 & Q47A==1
replace partyID=1 if ELECID==10 & Q47A==4.
replace partyID=1 if ELECID==11 & Q47A==1
replace partyID=1 if ELECID==11 & Q47A==4. 
replace partyID=1 if ELECID==12 & Q47A==1
replace partyID=1 if ELECID==12 & Q47A==5.
replace partyID=1 if ELECID==13 & Q47A==1
replace partyID=1 if ELECID==13 & Q47A==5. 
replace partyID=1 if ELECID==16 & Q47A==1.
replace partyID=1 if ELECID==17 & Q47A==1.
replace partyID=1 if ELECID==18 & Q47A==1
replace partyID=1 if ELECID==18 & Q47A==2
replace partyID=1 if ELECID==19 & Q47A==1
replace partyID=1 if ELECID==19 & Q47A==2
replace partyID=1 if ELECID==20 & Q47A==2.
replace partyID=1 if ELECID==21 & Q47A==2.
replace partyID=1 if ELECID==22 & Q47A==1.
replace partyID=1 if ELECID==22 & Q47A==4.
replace partyID=1 if ELECID==22 & Q47A==6.
replace partyID=1 if ELECID==23 & Q47A==2.
replace partyID=1 if ELECID==24 & Q47A==2.

gen opposeID=0.
replace opposeID=1 if partyID==0 & Q47==1

*** political knowledge
gen knowledge=Q10
gen highinformation=0
replace highinformation=1 if knowledge==1 & ELECID==5
replace highinformation=1 if knowledge==1 & ELECID==6
replace highinformation=1 if knowledge>.75 & ELECID==7
replace highinformation=1 if knowledge==1 & ELECID==9
replace highinformation=1 if knowledge==1 & ELECID==10
replace highinformation=1 if knowledge==1 & ELECID==12
replace highinformation=1 if knowledge==1 & ELECID==8
replace highinformation=1 if knowledge>.5 & ELECID==24
replace highinformation=1 if knowledge>.30 & ELECID==11
replace highinformation=1 if knowledge>.50 & ELECID==13
replace highinformation=1 if knowledge==1 & ELECID==22
replace highinformation=1 if knowledge==1 & ELECID==23
replace highinformation=1 if knowledge>.30 & ELECID==16
replace highinformation=1 if knowledge>.15 & ELECID==17
replace highinformation=1 if knowledge>.35 & ELECID==20
replace highinformation=1 if knowledge>.40 & ELECID==21
replace highinformation=1 if knowledge>.30 & ELECID==18
replace highinformation=1 if knowledge>.30 & ELECID==19


save "C:\Users\sgolder\Dropbox\OUP multilevel electoral behavior book\chapter 7\replication\ch7.dta", replace


log close
exit

